package com.gjy.pd.broker;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2023-01-17 11:45:02
 */
public class Client {

    public static void main(String[] args) {
        ChatRoom room = new ChatRoom();
        User tom = new User("Tom", room);
        User jerry = new User("Jerry", room);

        tom.showMsg("i am tom");
        jerry.showMsg("i am jerry");
    }

    private static class User {
        private final String name;
        private final ChatRoom chatRoom;

        public User(String name, ChatRoom chatRoom) {
            this.name = name;
            this.chatRoom = chatRoom;
        }

        public void showMsg(String msg) {
            this.chatRoom.showMsg(this, msg);
        }

        public String getName() {
            return name;
        }
    }

    private static class ChatRoom {
        public void showMsg(User user, String msg) {
            System.out.println("[" + user.getName() + "]: " + msg);
        }
    }
}
